package com.example.contactfragment;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.boyuan.huijiaoyu.R;
import com.example.newfragment.CTHAdapter;
import com.magicsoft.app.helper.StringUtils;
import com.magicsoft.constant.Constant;
import com.nostra13.universalimageloader.core.ImageLoader;

public class HomeContactSearchAdapter extends
		CTHAdapter<SearchPeople> {

	private ImageLoader imageLoader = ImageLoader.getInstance();

	public HomeContactSearchAdapter(Context context,
			List<SearchPeople> data) {
		// TODO Auto-generated constructor stub
		super(context, data);
		// this.options = options;
		// this.imageLoader = imageLoader;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		SearchPeople contactEntity = data.get(position);

		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(
					R.layout.home_contact_search_item, null);
			holder.imageView = (ImageView) convertView
					.findViewById(R.id.imageview);
			holder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

//		if (StringUtils.isImageLayout(contactEntity.getAvatar())) {
//			imageLoader.displayImage(contactEntity.getAvatar(),
//					holder.imageView);
		if (contactEntity.getUid() != null) {
			String uri = Constant.photourl + contactEntity.getUid();
			imageLoader.displayImage(uri, holder.imageView);
		} else {
			holder.imageView.setImageResource(R.drawable.default_header);
		}

		holder.tv_name.setText(contactEntity.getRealname());

		return convertView;
	}

	static class ViewHolder {
		ImageView imageView;
		TextView tv_name;
	}
}
